<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择日期" v-decorator="[ 'workdate', validatorRules.workdate]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomname', validatorRules.workroomname]" placeholder="请输入车间"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workroomno', validatorRules.workroomno]" placeholder="请输入车间编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename,workroomid,workroomno,workroomname,lineleadername"
						dest-fields="lineid,lineno,linename,workroomid,workroomno,workroomname,lineleader"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="线长" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'lineleader', validatorRules.lineleader]" placeholder="请输入线长"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="应到人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'shouldNumber', validatorRules.shouldNumber]" placeholder="请输入应到人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="实到人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'actualNumber', validatorRules.actualNumber]" placeholder="请输入实到人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="借入人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'borrowNumber', validatorRules.borrowNumber]" placeholder="请输入借入人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="调出人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lendNumber', validatorRules.lendNumber]" placeholder="请输入调出人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="迟到人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lateNumber', validatorRules.lateNumber]" placeholder="请输入迟到人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="请假人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'leaveNumber', validatorRules.leaveNumber]" placeholder="请输入请假人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="旷工人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'absentNumber', validatorRules.absentNumber]" placeholder="请输入旷工人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="制单人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['makeBy', validatorRules.makeBy]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="制单日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择制单日期" v-decorator="[ 'makeDate', validatorRules.makeDate]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'billno', validatorRules.billno]" placeholder="请输入单据编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'

  export default {
    name: "MesHrAttendanceSignModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JSelectUserByDep,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        workdate:{},
        workroomname:{},
        workroomno:{},
        linename:{},
        lineno:{},
        lineleader:{rules: [{ required: true, message: '请输入线长!' }]},
        shouldNumber:{rules: [{ required: true, message: '请输入应到人数!' }]},
        actualNumber:{rules: [{ required: true, message: '请输入实到人数!' }]},
        borrowNumber:{rules: [{ required: true, message: '请输入借入人数!' }]},
        lendNumber:{rules: [{ required: true, message: '请输入调出人数!' }]},
        lateNumber:{rules: [{ required: true, message: '请输入迟到人数!' }]},
        leaveNumber:{rules: [{ required: true, message: '请输入请假人数!' }]},
        absentNumber:{rules: [{ required: true, message: '请输入旷工人数!' }]},
        makeBy:{rules: [{ required: true, message: '请输入制单人!' }]},
        makeDate:{rules: [{ required: true, message: '请输入制单日期!' }]},
        billno:{rules: [{ required: true, message: '请输入单据编号!' }]},
        remark:{},
        },
        url: {
          add: '/mes-manpower/auto/mesHrAttendanceSign/add',
          edit: '/mes-manpower/auto/mesHrAttendanceSign/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'workdate','workroomname','workroomno','linename','lineno','lineleader','shouldNumber','actualNumber','borrowNumber','lendNumber','lateNumber','leaveNumber','absentNumber','makeBy','makeDate','billno','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'workdate','workroomname','workroomno','linename','lineno','lineleader','shouldNumber','actualNumber','borrowNumber','lendNumber','lateNumber','leaveNumber','absentNumber','makeBy','makeDate','billno','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>